import useMainStore from '@renderer/store/modules/useMainStore'
import { setPixi } from '@renderer/store/modules/usePixiStore'
import * as PIXI from 'pixi.js'
import init from './asset'
import getParams from './params'
import getFrame from './frame'
import getWuxing from './wuxing'
import type from './type'
import page from './page'
import ornament from './ornament'
import cutBtn from './cutBtn'
import creation from './creation'
import search from './search'
import modal from './modal'
// import diy from '../Diy'

export default async (): Promise<void> => {
  const mainStore = useMainStore()
  const app = await mainStore.getApp()
  const mainContainer = app.stage.getChildByLabel('main')
  const container = new PIXI.Container({ label: 'cardBook' })
  await init() // 卡册精灵
  const params = await getParams() // 参数
  // 边框
  const { downSprite, upSprite, bottomContainer, borderContainer } = await getFrame(params)
  const wuxingSprite: PIXI.Sprite[] = getWuxing(params) // 五行选项
  const searchContainer = search(params.textureSource) // 检索区域
  const typeContainer = type(params.textureSource) // 类型
  const pageContainer = await page(params.textureSource) // 翻页
  const ornamentContainer = ornament() // 装饰品
  const cutBtnContainer = await cutBtn() // 切换按钮
  const creationContainer = await creation() // 创作按钮
  const modalContainer = await modal() // 模态框

  // 添加到容器
  container.addChild(bottomContainer) //底色

  container.addChild(borderContainer) // 边框
  container.addChild(upSprite) // 上框
  container.addChild(downSprite) // 下框
  container.addChild(searchContainer) // 搜索框
  container.addChild(typeContainer) // 类型
  container.addChild(pageContainer) // 翻页
  container.addChild(ornamentContainer) // 装饰
  container.addChild(cutBtnContainer) // 切换按钮
  container.addChild(creationContainer) // 创作按钮
  // 添加五行选项
  wuxingSprite.forEach((item) => {
    container.addChild(item)
  })
  container.addChild(modalContainer) // 模态框

  setPixi('cardBook', container)
  mainContainer?.addChild(container)
}
